<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>addCaseToProjectPage</title>
    <style>
    table{border-collapse:collapse;border-spacing:0;border-left:1px solid #888;border-top:1px solid #888;margin: auto}
    th,td{border-right:1px solid #888;border-bottom:1px solid #888;padding:5px 15px;}
    th{font-weight:bold;}
    body{text-align: center}
    </style>
    {% load static %}
    <script type='text/javascript' src="/static/js/jquery.min.js"></script>
    <script type='text/javascript' src="/static/js/user.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("input[name='todo']").click(function(){
                var act = $(this).val();
                var projectId = $(this).parent().find("input[name='projectId']").val();
                var caseId = $(this).parent().find("input[name='caseId']").val();
                var scrf = $("input[name='csrfmiddlewaretoken']").val();
                todoType = 0;
                if(act=='取消'){
                    todoType = 0;
                }
                if(act=='绑定'){
                    todoType = 1;
                }
                if(act=='删除'){
                    todoType = 2;
                }
                $.ajax({
                    url:'/todoCaseAndProjectRelations/',
                    type:'POST',
                    data:{type:todoType,projectId:projectId,caseId:caseId,csrfmiddlewaretoken:scrf},
                    success:function(data){
                        if(data=='1'){
                            alert('操作成功');
                            window.location.reload();
                        }else{
                            alert('操作失败');
                            window.location.reload();
                        }
                    }
                });
            });
        });
    </script>
</head>
<body>
<div style="width: 80%;height:40px;background-color: aqua;margin: 0 auto ">
    <div style="float:left;margin-left: 10px;margin-top: 10px"><a href="#" name="projectManager">项目管理&nbsp;&nbsp;</a>|</div>
    <div style="float:left;margin-left: 10px;margin-top: 10px"><a href="#" name="testCaseManager">测试用例管理&nbsp;&nbsp;</a>|</div>
    <div style="float:left;margin-left: 10px;margin-top: 10px"><a href="#" name="bugCheck">bug情况查看&nbsp;&nbsp;</a>|</div>
    <div style="float:left;margin-left: 10px;margin-top: 10px"><a href="#" name="registerPage">注册新用户</a></div>
    <div style="float:right;margin-right:10px;margin-top: 10px"><a href="#" name="logout">退出</a></div>
    <div style="float:right;margin-right:10px;margin-top: 10px">登录人：{{ request.session.showName }}&nbsp;&nbsp;</div>
    <form method="post" name="dataForm">
        {% csrf_token %}
        <input type="hidden" name="dataInput" />
    </form>
</div><p></p>
    <table>
        <tr>
            <td style="text-align: left">项目名称</td>
            <td>{{ projectInfo.projectName }}</td>
        </tr>
    </table><p>
    <table>
        <tr>
            <td>序号</td>
            <td>case title</td>
            <td>是否绑定</td>
            <td>操作</td>
        </tr>
        {% for caseInfo in caseInfos %}
        <tr>
            <td>{{ forloop.counter }}</td>
            <td>{{ caseInfo.caseInfo.caseTitle }}</td>
            <td>
                {% if caseInfo.status == 1 %}<font color="green"> 已绑定</font>{% else %}<font color="red"> 未绑定</font>{% endif %}
            </td>
            <td>
                {% if caseInfo.status == 1 %}<input type="button" value="取消" name="todo"/> </font>{% else %}<input type="button" value="绑定" name="todo"/>{% endif %}
                <input type="button" name="todo" value="删除"/>
                <input type="hidden" name="projectId" value="{{ projectInfo.id }}"/>
                <input type="hidden" name="caseId" value="{{ caseInfo.caseInfo.id }}"/>
                <input type="hidden" name="status" value="{{ caseInfo.status }}"/>
            </td>
        </tr>
        {% endfor %}
    </table>
{% csrf_token %}
</body>
</html>